<template>
	<view class="process-container">
		<van-cell-group>
			<van-cell v-for="(item, index) in fileList" center :key="index" :title="item.name">
				<view slot="title">
					<view @click.stop="previewFile(item)" class="van-cell-text">单元格</view>
				</view>
				<van-button @click.stop="previewFile(item)" type="primary">
					查看
				</van-button>
			</van-cell>
		</van-cell-group>
	</view>
</template>

<script>
	import {
		getServerFileList
	} from '@/request/api.js'
	
	export default {
		data() {
			return {
				fileList: [],
				shareData: {
					title: '分享文件',
					path: '/pages/file_share/file_share',
					imageUrl: '',
					content: '',
					desc: ''
				},
				currentFile: null
			};
		},
		// onShareAppMessage(res) {
		// 	return {
		// 		title: this.shareData.title,
		// 		path: this.shareData.path,
		// 		imageUrl: this.shareData.imageUrl,
		// 		content: this.shareData.content,
		// 		desc: this.shareData.desc,
		// 		success: res => {
		// 			console.info(res)
		// 		}
		// 	}
		// },
		created() {
			this.init()
		},
		methods: {
			toShare(item) {
				uni.navigateTo({
					url: `/pages/file_share/file_share?filePath=${item.path}&fileName=${item.name}`,
				})
				// uni.share({
				// 	provider: 'weixin',
				// 	scene: "WXSceneSession",
				// 	type: 5,
				// 	imageUrl: 'https://bjetxgzv.cdn.bspapp.com/VKCEYUGU-uni-app-doc/962fc340-4f2c-11eb-bdc1-8bd33eb6adaa.png',
				// 	title: '欢迎体验uniapp',
				// 	miniProgram: {
				// 		id: 'gh_ba76db8018d2',
				// 		type: 0,
				// 		path: '/pages/index/index',
				// 		webUrl: ''
				// 	},
				// 	success: ret => {
				// 		console.log(JSON.stringify(ret));
				// 	}
				// })
			},
			previewFile(item) {
				console.log(item);
				uni.downloadFile({
					url: item.path,
					success: (res) => {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
							}
						});
					},
					fail: () => {
						uni.showToast({
							icon: 'none',
							title: '文件下载失败'
						})
					}
				})
			},
			init() {
				try {
					getServerFileList().then(res => {
						if (res.code !== 200) {
							throw 'error'
							return
						}
						this.fileList = res.result
						// uni.showToast({
						// 	title:	'请求完成'
						// })
					})
				} catch (e) {
					uni.showToast({
						title: '请求出错'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.process-container {
		// padding: 32rpx;

		.file-list {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			border: 1px solid #C0C0C0;

			.file-item {
				border-bottom: 1px solid #C0C0C0;
				padding: 8px 16px;
				box-sizing: border-box;
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.file-item-left {}

				.file-item-right {}
			}

			.file-item:last-child {
				border-bottom: none;
			}
		}
	}
</style>
